<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>

<script type="text/javascript" src="jquery-2.1.0.js"></script>

<script>

$(document).ready(function(){
	$('#itemCode').change(function(){
		$.get('PDT1020P11.do?itemCode='+$('#itemCode>option:selected').val(),function(data){
			$('#categoryName').val(data);
		});
	});
});

$(document).ready(function(){
	if($('#mode').val()=="V"){
		$('.in,select').attr('disabled', true);
		$('#delete').css({display:"none"});
		$('#modify').css({display:"none"});
		$('#save').css({display:"none"});
	}else if($('#mode').val()=="I"){
		$('.in,select').attr('disabled', false);
		$('#delete').css({display:"none"});
		$('#modify').css({display:"none"});
		$('#save').css({display:"inline"});
	} else if($('#mode').val()=="M"){
		$('.in,select').attr('disabled', true);
		$('#delete').css({display:"inline"});
		$('#modify').css({display:"inline"});
		$('#save').css({display:"none"});
	}
	
});

	function employeeSearchFn()
	{
	//	window.showModalDialog("PDT1020P2.do", window, "dialogWidth:800px;dialogHeight:600px;status:no;help:no");
	 	var frm=document.frm01;
		var title  = "searchPopUp";
		var status = "toolbar=no,directories=no,scrollbars=no,resizable=no,status=no,menubar=no,width=800, height=600, top=0,left=20"; 
		frm.target = title;    
		window.open("",title,status); 
		frm.action = "PDT1020P2.do";
		frm.submit(); 
	}
	
	function fileUploadFn(){
		var frm=document.frm01;
		frm.submit();
	}
	
	function deleteFn()
	{
		var frm=document.frm01;
		
		if(confirm("정말 삭제 하시겠습니까?")){
			
			$('.in,select').attr('disabled', false);
			frm.action = "PDT1020P13.do";
			frm.submit();
		}
	}
	
	function cancleFn(){
		
		if(confirm("정말 취소 하시겠습니까?")){
			self.close();	
		}
	}
	
	function saveFn(){
		var frm=document.frm01;
		
	//	if(confirm("저장 하시겠습니까?")){
			
			if(frm.productNumber.value==""||frm.productNumber.value==null){
				frm.productNumber.value=0;
			}
			if(frm.employeeCode.value==""||frm.employeeCode.value==null){
				frm.employeeCode.value=0;
			}
			frm.target="_self";
			frm.action = "PDT1020P14.do";
			frm.submit();
	//	}
	}
	
	$(document).ready(function(){
		$('#modify').click(function(){
			$('.in,select').attr('disabled', false);
			$('#modify').css({display:"none"});
			$('#delete').css({display:"inline"});
			$('#save').css({display:"inline"});
			
		});
	});
	
	function downLoadFn(attachedFileName){
		var frm=document.frm01;
		frm.action = "download.do?attachedFileName="+attachedFileName;
		frm.submit();
	}
	function numCheck(){
		
		if(!((event.keyCode>=48 && event.keyCode<=57)||
				(event.keyCode>=96 && event.keyCode<=105)||event.keyCode==8||event.keyCode==9)){
			
			event.returnValue=false;
		}
	}
		
	
</script>
</head>
<body>
<form name="frm01" method="post" enctype="multipart/form-data">
	<input id="mode" type="hidden" value="${mode }">
	${msg}
		<center>
			<table border="1" rules="all" cellspacing="0" cellpadding="5" width="100%">
				<tr>
					<td  align="center"><font size="1">주담당자 사원번호</font></td>
					<td ><input class="in" id="empNo" name="employeeCode" type="text" value="${productDetailInfo.employeeCode}"  readonly="readonly"> 
					<font size="1"><input class="in" type="button" onclick="employeeSearchFn()" value="검색"></font></td>
					<td align="center"><font size="1">주담당자성명/소속부서</font></td>
					<td ><input class="in" name="employeeName" type="text" value="${productDetailInfo.employeeName}" readonly="readonly" >
					   	<input class="in" name="departmentName" type="text" value="${productDetailInfo.departmentName}" readonly="readonly"></td>
				</tr>
				<tr>
					<td align="center"><font size="1">상품코드</font></td>
					<td colspan="1" align="left"><input class="in" name="productCode" type="text" value="${productDetailInfo.productCode}"  > 
					<td align="center"><font size="1">상품명</font></td>
					<td colspan="1" align="left"><input class="in" name="productName" type="text" value="${productDetailInfo.productName}"  > 
				</tr>
				<tr>
					<td align="center"><font size="1">품목명</font></td>
					<td colspan="1">
						<select id="itemCode" name="itemCode">
						<option value=""></option>
							<c:forEach var="b"  items="${model}">
							<c:set var="fl" value="${false}"></c:set>
							<c:if test="${b.codeType=='ITEM'}">
									<c:if test="${b.codeDetail==productDetailInfo.itemCode }">
									<option value="${b.codeDetail}" selected>${b.codeName }</option>
									<c:set var="fl" value="${true}"></c:set>
								</c:if>
							<c:if test="${fl!=true}">
									<option value="${b.codeDetail}" >${b.codeName }</option>
							</c:if>
							</c:if>
						</c:forEach>
					</select>
					</td>
					<td align="center"><font size="1">카테고리</font></td>
					<td colspan="1"><input class="in" id="categoryName" type="text" name="categoryName" value="${productDetailInfo.categoryName }" readonly="readonly"> </td>
				</tr>
					<tr>
					<td align="center"><font size="1">제조사</font></td>
					<td colspan="1">
						<select name="companyCode">
						<option value=""></option>
							<c:forEach var="b"  items="${model}">
							<c:set var="fl" value="${false}"></c:set>
							<c:if test="${b.codeType=='COMPANY'}">
									<c:if test="${b.codeDetail==productDetailInfo.companyCode }">
									<option value="${b.codeDetail}" selected>${b.codeName }</option>
									<c:set var="fl" value="${true}"></c:set>
								</c:if>
							<c:if test="${fl!=true}">
									<option value="${b.codeDetail}" >${b.codeName }</option>
							</c:if>
							</c:if>
						</c:forEach>
					</select>
					
					<td align="center"><font size="1">상품번호 </font></td>
					<td colspan="1"><input class="in" type="text" name="productNumber" value="${productDetailInfo.productNumber}" readonly="readonly"> </td>
				</tr>
				<tr>
					<td align="center"><font size="1">규  격</font></td>	
					<td colspan="3"><textarea class="in" name="productSize" style="height:100px;width:700px;">${productDetailInfo.productSize}</textarea>
				</tr>
				<tr>
					<td align="center"><font size="1">단  위</font></td>
					<td colspan="1">
						<select name="unitMeasureCode">
						<option value=""></option>
							<c:forEach var="b"  items="${model}">
							<c:set var="fl" value="${false}"></c:set>
							<c:if test="${b.codeType=='MEASURE'}">
									<c:if test="${b.codeDetail==productDetailInfo.unitMeasureCode }">
									<option value="${b.codeDetail}" selected>${b.codeName }</option>
									<c:set var="fl" value="${true}"></c:set>
								</c:if>
							<c:if test="${fl!=true}">
									<option value="${b.codeDetail}" >${b.codeName }</option>
							</c:if>
							</c:if>
						</c:forEach>
					</select>
					
					<td align="center"><font size="1">단  가 </font></td>
					<td colspan="1"><input class="in" type="text" name="unitPrice" value="${productDetailInfo.unitPrice }" onkeydown="numCheck()" > </td>
				</tr>
				<tr>
					<td align="center"><font size="1">파일첨부</font></td>
					<td colspan="3"><input class="in" type="file" name="attachedFile">
									<c:if test="${productDetailInfo.attachedFileName!=null && productDetailInfo.attachedFileName!=''}">
									<input type="hidden" name="attachedFileName" value="${productDetailInfo.attachedFileName }">
										<input class="in" type="button" value="${productDetailInfo.attachedFileName } : 다운로드"
											onclick="downLoadFn('${productDetailInfo.attachedFileName }')">
									</c:if>
				</tr>
				<tr>
					<td colspan="4" align="center">
						<input id="delete" type="button" onclick="deleteFn()" value="삭제">
						<input id="modify" type="button"  value="수정">
						<input id="save" type="button" onclick="saveFn()" value="저장">
						<input id="cancle" type="button" onclick="cancleFn()" value="취소">
					</td>
				</tr>
			</table>
			</center>
			</form>

</body>
</html>